package com.rfid.assistant.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import com.rfid.assistant.R;
import com.rfid.socketio.SocketIoInstance;
import com.rfid.assistant.activity.adapter.DeviceAdapter;
import com.rfid.assistant.base.BaseListActivity;
import com.rfid.assistant.base.BasePresenter;
import com.rfid.webp2plib.SignalClient;
import com.rfid.webp2plib.User;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RemoteMainActivity extends BaseListActivity<DeviceAdapter, User, BasePresenter> implements SignalClient.UserListener{



    public static void startActivity(Context context,boolean isConfig) {
        Intent intent = new Intent();
        intent.putExtra("config",isConfig);
        intent.setClass(context,RemoteMainActivity.class);
        context.startActivity(intent);
    }

    @BindView(R.id.txt)
    TextView mCenterText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        if (!SocketIoInstance.INSTANCE.isConnect()) {
            Toast.makeText(this,"服务器连接失败",Toast.LENGTH_SHORT).show();
            finish();
        }
        SocketIoInstance.INSTANCE.getClient().setUserListener(this);
        mCenterText.setText(SocketIoInstance.INSTANCE.getClient().getClientId());
    }

    @Override
    protected void onResume() {
        super.onResume();
        //        SocketIoInstance.INSTANCE.getClient().getLogins();
        SocketIoInstance.INSTANCE.getClient().login(this,"列表登录");
    }

    @Override
    protected int getCountDownTime() {
        return 0;
    }

    @Override
    public BasePresenter getPresenter() {
        return null;
    }


    @Override
    protected int getLayoutResId() {
        return R.layout.activity_remote_main;
    }

    @Override
    protected DeviceAdapter getAdapter() {
        return new DeviceAdapter(mData);
    }

    @Override
    protected int getRecyclerViewId() {
        return R.id.recyclerView;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onClick(User user) {
        SocketIoInstance.INSTANCE.getClient().setRemoteIp(user.getId());
        if (getIntent().getBooleanExtra("config",false)) {
            SafeDoorConfigActivity.startActivity(this,user.getId(),false,true);
        } else {
            RemoteSRActivity.startActivity(this);
        }
    }

    @Override
    public void onLogin(String id, List<User> users) {
        System.out.println("onLogin > " + users);
        setData(users);
    }

    @Override
    public void onConnect(String id) {
    }

    @Override
    public void onDisconnect() {

    }
}